package com.aijk.web.admin.controller.openapi;

import com.aijk.ehm.api.SemStepApi;
import com.aijk.ehm.captcha.api.CaptchaApi;
import com.aijk.ehm.captcha.entity.CaptchaCreateRes;
import com.aijk.ehm.captcha.entity.CaptchaType;
import com.aijk.ehm.captcha.entity.SmsCaptchaCreateReq;
import com.aijk.ehm.model.EhmResident;
import com.aijk.ehm.model.SemStep;
import com.aijk.ehm.model.qo.SemStepQo;
import com.aijk.web.admin.config.Constant;
import com.aijk.web.admin.controller.openapi.entity.ApiResponse;
import com.aijk.web.admin.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@Controller
public class CaptchaController extends ApiBaseController {

    private static final Logger logger = LoggerFactory.getLogger(CaptchaController.class);


    @Autowired
    private CaptchaApi captchaApi;

    /**
     * @param mobile
     * @param key {1:绑定手机 2：找回密码}
     * @param len
     * @return
     */
    @RequestMapping(path = "app/captcha/send", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object captchaSend(@RequestParam(name = "mobile",required = true) String mobile,@RequestParam(name = "key",required = true) String key,@RequestParam(name = "len",defaultValue = "4") int len) {
        ApiResponse response = new ApiResponse();
        SmsCaptchaCreateReq req = new SmsCaptchaCreateReq();
        req.setType(CaptchaType.SMS);
        req.setMobile(mobile);
        req.setKey(Constant.CAPTCHA_KEY+key);
        req.setLen(len);
        CaptchaCreateRes res = captchaApi.create(req);
        response.setData(res);
        return response;
    }

}
